<template>
  <div>
    <span class="title">{{ product.title }}</span>
    <el-form :model="product" label-position="right" :inline="true">
      <el-form-item label="可用库存" label-width="135px">
        <el-input-number v-model="stock.amount"></el-input-number>
      </el-form-item>
      <el-form-item label="冻结库存" label-width="135px">
        <el-input-number v-model="stock.frozen" disabled></el-input-number>
      </el-form-item>
    </el-form>
    <div style="text-align: right; padding-right: 40px">
      <el-button @click="$emit('dismiss')">取 消</el-button>
      <el-button type="primary" @click="submitStock">确 定</el-button>
    </div>
  </div>
</template>

<script setup>
import api from '@/api'
import { ElNotification } from 'element-plus'
const emit = defineEmits(['dismiss'])


const {product, stock} = defineProps({
    product: Object,
    stock: Object,
  })

    /**
     * 修改指定商品的库存数量
     */
async function submitStock() {
  try {
    await api.warehouse.updateStock(product.id, stock.amount)
    ElNotification({
      title: '操作成功',
      message: '商品信息已修改',
      type: 'success',
    })
    emit('dismiss')
  } catch (e) {
    ElNotification({ title: '操作失败', message: e.message, type: 'error' })
  }
}


</script>

<style scoped>
.title {
  font-size: 20px;
  padding-bottom: 30px;
  display: block;
}
</style>
